package com.lazy.dbdemo.service;

import java.sql.Timestamp;
import java.util.Date;
import java.util.List;

import com.lazy.dbdemo.bean.GpsBean;
import com.lazy.dbdemo.bean.HostCurstatus;
import com.lazy.lib.db.JDBCConfig;
import com.lazy.lib.db.bonecp.SingleDBImpl;

/**
 * 数据库操作的业务处理
 * 
 * @author luodan
 *
 */
public class JdbcServiceImpl {

    private SingleDBImpl dbImpl;
    
    private static JdbcServiceImpl serviceImpl;
    
    public synchronized static JdbcServiceImpl getService(JDBCConfig config) {
        if (serviceImpl == null) {
            serviceImpl = new JdbcServiceImpl(config);
        }
        return serviceImpl;
    }
    
    private JdbcServiceImpl(JDBCConfig config){
        dbImpl = new SingleDBImpl(config);
    }
    
    public Date getDBsysTime() {
        return dbImpl.getDBsysTime();
    }
    
    public List<GpsBean> queryCurrentGpsData(Date dbLastUpdateSysTime) {
        return dbImpl.queryForList(JdbcSql.QUERY_CURRENT_GPS_SDDL, new Object[] { new Timestamp(dbLastUpdateSysTime.getTime()) }, 
                GpsBean.class, 0);
    }
    
    public List<HostCurstatus> queryHostCurstatus() {
        return dbImpl.queryForList(JdbcSql.QUERY_HOST_CURSTATUS, null, 
                HostCurstatus.class, 0);
    }
    
}
